﻿using System;
using MyWeb.Business;

namespace MyWeb.Controls
{
    public partial class u_top : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ShowHeader();
                ShowMenu();
            }
        }
        private void ShowHeader()
        {
            var s = "<div class=\"header\">";
            var list = AdvertiseService.Advertise_GetByTop("1", "Position = '2' and Active = '1'", "");
            if(list.Count > 0)
            {
                s += "<div class=\"banner\">";
                s += "<div class=\"box-banner\">";
                foreach (var t in list)
                {
                    if (t.Images.IndexOf(".swf") > 0)
                    {
                        s += "<script language='javascript'>playfile('" + t.Images + "', '" + t.Width + "', '" + t.Height + "', true, '', '', '');</script>";
                    }
                    else
                    {
                        s += "<img class=\"style1\" src='" + t.Images + "' width = '" + t.Width + "' height= '" + t.Height + "' alt='" + t.Name + "'/> ";
                    }
                }
                s += "</div>";
                s += "</div><div class=\"clean-fix\"></div>";
            }
            s += "</div>";
            ltrheader.Text = s;
            #region html code

            /*
             <div class="header">
                <div class="banner">
                    <div class="box-banner">
                        <img src="images/banner.jpg" alt="banner" />
                    </div>
                </div>
                <div class="clean-fix"></div>
            </div>
             */
            #endregion
        }
        private void ShowMenu()
        {
            var s = "<div class=\"bg-menu\">\n";
            var list = PagesService.Pages_GetByTop("", "Position = '1' and Active = '1'", "[Level]");
            if (list.Count > 0)
            {
                s += "<div id=\"smoothmenu1\" class=\"ddsmoothmenu\"><ul>";
                for (int i = 1; i < list.Count; i++)
                {
                    if (list[i - 1].Level.Length < list[i].Level.Length)
                    {
                        s += "<li><a href=\"" + list[i - 1].Link + "\">" + list[i - 1].Name + "</a><ul>\n";
                    }
                    else if (list[i - 1].Level.Length == list[i].Level.Length)
                    {
                        s += "<li><a href=\"" + list[i - 1].Link + "\">" + list[i - 1].Name + "</a></li>\n";
                    }
                    else if (list[i - 1].Level.Length > list[i].Level.Length)
                    {
                        s += "<li><a href=\"" + list[i - 1].Link + "\">" + list[i - 1].Name + "</a></li>\n";
                        var n = (list[i - 1].Level.Length - list[i].Level.Length) / 5;
                        s += Inma(n);
                    }
                }
                if (list[list.Count - 2].Level.Length < list[list.Count - 1].Level.Length)
                {
                    s += "<li><a href=\"" + list[list.Count - 1].Link + "\">" + list[list.Count - 1].Name + "</a></li>\n";
                    var k = (list[list.Count - 1].Level.Length - 5) / 5;
                    s += Inma(k);
                }
                else
                {
                    s += "<li><a href=\"" + list[list.Count - 1].Link + "\">" + list[list.Count - 1].Name + "</a></li>\n";
                }
                s += "</ul></div>";
            }
            s += "</div>\n";
            ltrmenu.Text = s;
        }
        string Inma(int a)
        {
            string str = "";
            for (int j = 1; j <= a; j++)
            {
                str += "</ul></li>";
            }
            return str;
        }
    }
}